/*     */ package dm.jdbc.dbaccess.ssl;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.security.KeyManagementException;
/*     */ import java.security.KeyStore;
/*     */ import java.security.KeyStoreException;
/*     */ import java.security.NoSuchAlgorithmException;
/*     */ import java.security.Principal;
/*     */ import java.security.Provider;
/*     */ import java.security.SecureRandom;
/*     */ import java.security.Security;
/*     */ import java.security.UnrecoverableKeyException;
/*     */ import java.security.cert.CertificateException;
/*     */ import java.security.cert.X509Certificate;
/*     */ import java.util.Properties;
/*     */ import javax.net.ssl.KeyManagerFactory;
/*     */ import javax.net.ssl.SSLContext;
/*     */ import javax.net.ssl.TrustManager;
/*     */ import javax.net.ssl.TrustManagerFactory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FullDuplexValidatingFactory
/*     */   extends WrappedFactory
/*     */ {
/*  45 */   private String algorithm = "SunX509";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  51 */   private KeyStore keyStore = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  56 */   private String keystorePass = "changeit";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  61 */   private String keystoreType = "JKS";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  66 */   private String protocol = "TLSv1";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  71 */   private String keystoreFile = "";
/*     */   
/*  73 */   private String m_curUser = "";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public FullDuplexValidatingFactory(Properties prop)
/*     */     throws IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException, CertificateException
/*     */   {
/*     */     try
/*     */     {
/*  95 */       initKeyStore(prop);
/*     */       
/*  97 */       checkUser(prop.getProperty("user"));
/*     */       
/*  99 */       initSSLContext();
/*     */     } catch (IOException ioe) {
/* 101 */       throw ioe;
/*     */     } catch (KeyStoreException kse) {
/* 103 */       throw kse;
/*     */     } catch (NoSuchAlgorithmException nsae) {
/* 105 */       throw nsae;
/*     */     } catch (UnrecoverableKeyException unreke) {
/* 107 */       throw unreke;
/*     */     } catch (KeyManagementException kmex) {
/* 109 */       throw kmex;
/*     */     } catch (CertificateException ce) {
/* 111 */       throw ce;
/*     */     }
/*     */   }
/*     */   
/*     */   /* Error */
/*     */   private void initKeyStore(Properties prop)
/*     */     throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException
/*     */   {
/*     */     // Byte code:
/*     */     //   0: aconst_null
/*     */     //   1: astore_2
/*     */     //   2: aload_0
/*     */     //   3: aload_0
/*     */     //   4: getfield 45	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystoreType	Ljava/lang/String;
/*     */     //   7: invokestatic 93	java/security/KeyStore:getInstance	(Ljava/lang/String;)Ljava/security/KeyStore;
/*     */     //   10: putfield 37	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keyStore	Ljava/security/KeyStore;
/*     */     //   13: aload_0
/*     */     //   14: aload_1
/*     */     //   15: ldc 60
/*     */     //   17: invokevirtual 62	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
/*     */     //   20: putfield 55	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:m_curUser	Ljava/lang/String;
/*     */     //   23: aload_0
/*     */     //   24: aload_1
/*     */     //   25: ldc 99
/*     */     //   27: aload_0
/*     */     //   28: getfield 41	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystorePass	Ljava/lang/String;
/*     */     //   31: invokevirtual 101	java/util/Properties:getProperty	(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
/*     */     //   34: putfield 41	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystorePass	Ljava/lang/String;
/*     */     //   37: aload_1
/*     */     //   38: ldc 104
/*     */     //   40: invokevirtual 62	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
/*     */     //   43: astore_3
/*     */     //   44: aload_0
/*     */     //   45: aload_0
/*     */     //   46: aload_3
/*     */     //   47: invokespecial 106	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:getKeyStorePath	(Ljava/lang/String;)Ljava/lang/String;
/*     */     //   50: putfield 53	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystoreFile	Ljava/lang/String;
/*     */     //   53: new 109	java/io/FileInputStream
/*     */     //   56: dup
/*     */     //   57: aload_0
/*     */     //   58: getfield 53	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystoreFile	Ljava/lang/String;
/*     */     //   61: invokespecial 111	java/io/FileInputStream:<init>	(Ljava/lang/String;)V
/*     */     //   64: astore_2
/*     */     //   65: aload_0
/*     */     //   66: getfield 37	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keyStore	Ljava/security/KeyStore;
/*     */     //   69: aload_2
/*     */     //   70: aload_0
/*     */     //   71: getfield 41	dm/jdbc/dbaccess/ssl/FullDuplexValidatingFactory:keystorePass	Ljava/lang/String;
/*     */     //   74: invokevirtual 113	java/lang/String:toCharArray	()[C
/*     */     //   77: invokevirtual 119	java/security/KeyStore:load	(Ljava/io/InputStream;[C)V
/*     */     //   80: goto +28 -> 108
/*     */     //   83: astore_3
/*     */     //   84: aload_3
/*     */     //   85: athrow
/*     */     //   86: astore_3
/*     */     //   87: aload_3
/*     */     //   88: athrow
/*     */     //   89: astore_3
/*     */     //   90: aload_3
/*     */     //   91: athrow
/*     */     //   92: astore_3
/*     */     //   93: aload_3
/*     */     //   94: athrow
/*     */     //   95: astore 4
/*     */     //   97: aload_2
/*     */     //   98: ifnull +7 -> 105
/*     */     //   101: aload_2
/*     */     //   102: invokevirtual 123	java/io/FileInputStream:close	()V
/*     */     //   105: aload 4
/*     */     //   107: athrow
/*     */     //   108: aload_2
/*     */     //   109: ifnull +7 -> 116
/*     */     //   112: aload_2
/*     */     //   113: invokevirtual 123	java/io/FileInputStream:close	()V
/*     */     //   116: return
/*     */     // Line number table:
/*     */     //   Java source line #129	-> byte code offset #0
/*     */     //   Java source line #132	-> byte code offset #2
/*     */     //   Java source line #135	-> byte code offset #13
/*     */     //   Java source line #139	-> byte code offset #23
/*     */     //   Java source line #142	-> byte code offset #37
/*     */     //   Java source line #143	-> byte code offset #44
/*     */     //   Java source line #145	-> byte code offset #53
/*     */     //   Java source line #146	-> byte code offset #65
/*     */     //   Java source line #147	-> byte code offset #80
/*     */     //   Java source line #148	-> byte code offset #84
/*     */     //   Java source line #149	-> byte code offset #86
/*     */     //   Java source line #150	-> byte code offset #87
/*     */     //   Java source line #151	-> byte code offset #89
/*     */     //   Java source line #152	-> byte code offset #90
/*     */     //   Java source line #153	-> byte code offset #92
/*     */     //   Java source line #154	-> byte code offset #93
/*     */     //   Java source line #155	-> byte code offset #95
/*     */     //   Java source line #156	-> byte code offset #97
/*     */     //   Java source line #157	-> byte code offset #101
/*     */     //   Java source line #159	-> byte code offset #105
/*     */     //   Java source line #156	-> byte code offset #108
/*     */     //   Java source line #157	-> byte code offset #112
/*     */     //   Java source line #161	-> byte code offset #116
/*     */     // Local variable table:
/*     */     //   start	length	slot	name	signature
/*     */     //   0	117	0	this	FullDuplexValidatingFactory
/*     */     //   0	117	1	prop	Properties
/*     */     //   1	112	2	istream	java.io.FileInputStream
/*     */     //   43	4	3	filePathTemp	String
/*     */     //   83	2	3	ioe	IOException
/*     */     //   86	2	3	kse	KeyStoreException
/*     */     //   89	2	3	nsae	NoSuchAlgorithmException
/*     */     //   92	2	3	ce	CertificateException
/*     */     //   95	11	4	localObject	Object
/*     */     // Exception table:
/*     */     //   from	to	target	type
/*     */     //   2	80	83	java/io/IOException
/*     */     //   2	80	86	java/security/KeyStoreException
/*     */     //   2	80	89	java/security/NoSuchAlgorithmException
/*     */     //   2	80	92	java/security/cert/CertificateException
/*     */     //   2	95	95	finally
/*     */   }
/*     */   
/*     */   private void checkUser(String user)
/*     */     throws KeyStoreException
/*     */   {
/* 168 */     X509Certificate cert = (X509Certificate)this.keyStore.getCertificate("1");
/* 169 */     String userName = findCNname(cert.getSubjectDN().getName());
/* 170 */     if (!userName.equals(user)) {
/* 171 */       throw new KeyStoreException();
/*     */     }
/*     */   }
/*     */   
/*     */   private String findCNname(String strDN) {
/* 176 */     String regstr = "CN=";
/* 177 */     int begin = strDN.indexOf(regstr);
/* 178 */     int end = strDN.indexOf(",", begin);
/*     */     
/* 180 */     return strDN.substring(begin + regstr.length(), end);
/*     */   }
/*     */   
/*     */   private String getKeyStorePath(String strPath)
/*     */   {
/* 185 */     String strOrgPath = System.getProperty("DM_HOME") + File.separator + 
/* 186 */       "bin" + File.separator + "client_ssl" + File.separator + 
/* 187 */       this.m_curUser;
/*     */     
/*     */ 
/* 190 */     if ((strPath != null) && (strPath.length() > 0)) {
/* 191 */       strOrgPath = strPath;
/*     */     }
/* 193 */     return strOrgPath + File.separator + ".keystore";
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void initSSLContext()
/*     */     throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException
/*     */   {
/*     */     try
/*     */     {
/* 213 */       Security.addProvider((Provider)Class.forName(
/* 214 */         "com.sun.net.ssl.internal.ssl.Provider").newInstance());
/*     */     }
/*     */     catch (Throwable localThrowable) {}
/*     */     
/*     */ 
/*     */ 
/* 220 */     SSLContext context = SSLContext.getInstance(this.protocol);
/*     */     
/*     */ 
/* 223 */     KeyManagerFactory keyManagerFactory = 
/* 224 */       KeyManagerFactory.getInstance(this.algorithm);
/* 225 */     keyManagerFactory.init(this.keyStore, this.keystorePass.toCharArray());
/*     */     
/*     */ 
/*     */ 
/* 229 */     TrustManagerFactory tmf = TrustManagerFactory.getInstance(this.algorithm);
/* 230 */     tmf.init(this.keyStore);
/* 231 */     TrustManager[] tm = tmf.getTrustManagers();
/*     */     
/*     */ 
/* 234 */     context.init(keyManagerFactory.getKeyManagers(), tm, 
/* 235 */       new SecureRandom());
/*     */     
/* 237 */     this._factory = context.getSocketFactory();
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\dbaccess\ssl\FullDuplexValidatingFactory.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */